package com.lagou;

import org.junit.Test;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;

import java.util.HashSet;
import java.util.Set;

public class JedisTestCase {

    @Test
    public void testJedisCluster()throws Exception{
        //创建jedisCluster对象，有一个参数 nodes是Set类型，Set包含若干个HostAndPort对象
        Set<HostAndPort> nodes = new HashSet<HostAndPort>();
        nodes.add(new HostAndPort("192.168.1.31",6380));
        nodes.add(new HostAndPort("192.168.1.31",6381));
        nodes.add(new HostAndPort("192.168.1.32",6380));
        nodes.add(new HostAndPort("192.168.1.32",6381));
        nodes.add(new HostAndPort("192.168.1.33",6380));
        nodes.add(new HostAndPort("192.168.1.33",6381));
        nodes.add(new HostAndPort("192.168.1.36",6380));
        nodes.add(new HostAndPort("192.168.1.36",6381));
        JedisCluster jedisCluster = new JedisCluster(nodes);

        for (int i = 0; i <3 ; i++) {
            jedisCluster.set("lagouchenhuanyu"+i, "my www jedis2"+"chen"+i);
            String str = jedisCluster.get("linyoka"+i);
            System.out.println(str);
        }
        //使用jedisCluster操作redis

        //关闭连接池
        //jedisCluster.close();
    }



}
